// merchant//alliance/menber/index.js
const app = getApp();
const utils = require('../../utils/util.js');
Page({

  /**
   * 联盟会员
   * 页面的初始数据
   */
  data: {
    allianceId: 0,
    memberList:[],
    CurrentPage: 1,
    loadingMoreHidden: 1,
    meruid: 0//联盟内某商家
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.allianceId){
      let meruid = 0;
      if(options.meruid){
        meruid = options.meruid
      }
      this.getMemberList(options.allianceId,meruid);
      this.setData({
        allianceId: options.allianceId,
        meruid: meruid
      })
    }
    
  },
  
  getMemberList: function(allianceId,meruid){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Alliance/GetUserList?allianceId=' + allianceId + '&page=' + that.data.CurrentPage,
      success: function(res){
        if(res.data.Code == 0){
          let list = res.data.Data.Items;
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.memberList;
            list = preGoods.concat(list);
          }
          if(list.length>0){
            for(let i = 0; i < list.length; i++){
              list[i].Avatar = utils.formatAvater(list[i].Avatar, 'https://static.711688.net.cn/upload/card/source/');
              list[i].ShareAvatar = utils.formatAvater(list[i].ShareAvatar, 'https://static.711688.net.cn/upload/card/source/');
              list[i].Date = list[i].CreateTime.substr(0,10);
              list[i].time = list[i].CreateTime.substr(11,8);
            }
          }
          that.setData({
            memberList: list,
            loadingMoreHidden: res.data.Data.TotalPages
          })
        }
      }
    })
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadMore();
  },

  loadMore: function(){
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getMemberList(that.data.allianceId,that.data.meruid);
    } else {
      return
    }
  }
})